package com.linys.scala.qf.day04_implicit.generic

/**
  * 上界
  */
class UpperBoundsDemo_02[T <: Comparable[T]] {
  // 比较的方法
  def chooser(first: T, second: T, third: T): T = {
    if (first.compareTo(second) > 0 && first.compareTo(third) > 0)
      first
    else if (second.compareTo(first) > 0 && second.compareTo(third) > 0)
      second
    else
      third
  }
}

object Chooser {
  def main(args: Array[String]): Unit = {
    val chooser = new UpperBoundsDemo_02[Girl]
    val g1 = new Girl("mimi", 97, 31)
    val g2 = new Girl("bingbing", 95, 30)
    val g3 = new Girl("zzz", 95, 20)
    val girl = chooser.chooser(g1, g2, g3)
    println(girl.name)
    println(g2.compareTo(g1))
    println(g2.compareTo(g3))
  }
}

class Girl(val name: String, val faceValue: Int, val age: Int) extends Comparable[Girl] {
  override def compareTo(that: Girl): Int = {
    if (this.faceValue != that.faceValue) {
      this.faceValue - that.faceValue
    } else {
      that.age - this.age
    }
  }
}

